﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.IO;

namespace Compressor
{
    /// <summary>
    /// 保存 js文件
    /// </summary>
    public class StaticFileSave
    {
        /// <summary>
        /// 要保存的文件路径
        /// </summary>
        public string FileName { get; set; }
        /// <summary>
        /// 保存文件的编码
        /// </summary>
        public Encoding ContentType { get; set; }

        public StaticFileSave(string filename)
        {
            this.FileName = filename;
            this.ContentType = Encoding.UTF8;
        }
        public void DoSave(string content)
        {
            try
            {
                FileStream fileStream = new FileStream(FileName, FileMode.Create, FileAccess.Write);
                StreamWriter writer = new StreamWriter(fileStream, ContentType);
                writer.Write(content);
                writer.Close();
                fileStream.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("保存内容到文件失败，错误描述：" + ex.Message);
            }
        }


    }
}
